﻿#include "DockWidgetInfo.h"
#include "ui_DockWidgetInfo.h"

DockWidgetInfo::DockWidgetInfo(QWidget *parent) :
    QDockWidget(parent),
    ui(new Ui::DockWidgetInfo)
{
    ui->setupUi(this);
    connect(ui->pushButtonMeasure, &QPushButton::clicked, this, &DockWidgetInfo::detectTriggered);
    connect(ui->pushButtonRecipe, &QPushButton::clicked, this, &DockWidgetInfo::loadRecipeTriggered);
}

QPair<QString, QString> DockWidgetInfo::panelID()
{
    m_leftPanelID = ui->lineEditPanelIDLeft->text();
    m_rightPanelID = ui->lineEditPanelIDRight->text();
    return QPair<QString, QString>(m_leftPanelID, m_rightPanelID);
}


void DockWidgetInfo::onRobotConnected()
{
    ui->labelRobotState->setText("Connected to PLC");
}

void DockWidgetInfo::onRobotDisconnected()
{
    ui->labelRobotState->setText("Disconnect from PLC");
}

void DockWidgetInfo::setRobotState(QString str)
{
    ui->labelRobotState->setText(str);
}

void DockWidgetInfo::setRecipeName(QString recipeName)
{
    ui->labelRecipeName->setText(recipeName);
}

DockWidgetInfo::~DockWidgetInfo()
{
    delete ui;
}

void DockWidgetInfo::setRightPanelInfo(double x_mm, double y_mm, double theta, double score)
{
    ui->lineEditX2->setText(QString::number(x_mm, 'f', 3));
    ui->lineEditY2->setText(QString::number(y_mm, 'f', 3));
    ui->lineEditT2->setText(QString::number(theta, 'f', 3));
    ui->labelScore2->setNum(score);
}

void DockWidgetInfo::setLeftPanelInfo(double x_mm, double y_mm, double theta, double score)
{
    ui->lineEditX1->setText(QString::number(x_mm, 'f', 3));
    ui->lineEditY1->setText(QString::number(y_mm, 'f', 3));
    ui->lineEditT1->setText(QString::number(theta, 'f', 3));
    ui->labelScore1->setNum(score);
}

void DockWidgetInfo::setText(QString text)
{
    ui->labelRobotState->setText(text);
}

void DockWidgetInfo::setPanelID(QString panelID_L, QString panelID_R)
{
    m_leftPanelID = panelID_L;
    m_rightPanelID = panelID_R;

    ui->lineEditPanelIDLeft->setText(panelID_L);
    ui->lineEditPanelIDRight->setText(panelID_R);
}
